﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using ImageRecognition2.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;
using LowLevelGraphics.ColorSpaces;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Adjust Hue / Saturation / Lightness
    /// </summary>
    public class ActionHueSaturationLightness : AbstractCommand
    {
        private float m_Hue = 0.0f;
        private float m_Saturation = 0.0f;
        private float m_Brightness = 0.0f;

        protected BaseImageFilter m_Filter = null;

        /// <summary>
        /// 
        /// </summary>
        public ActionHueSaturationLightness()
        {
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormHueSaturationLightness formFilter = new FormHueSaturationLightness();
            if (formFilter.ShowDialog() != DialogResult.OK) return;

            formFilter.trackBarHue.Scroll += delegate(object senderTemp, EventArgs eTemp)
            {
                Bitmap formFilterpictureBox1BackgroundImageClone = (Bitmap)formFilter.imgOriginal.Clone();
                BaseImageFilter baseImageFilter = null;
                //baseImageFilter = (BaseImageFilter)Activator.CreateInstance(m_Filter.GetType(), new object[] { (int)formFilter.trackbAmount.Value });

                baseImageFilter =  new PerPixelFilter(new PerPixelFilter.PerPixelFilterDelegate(
                delegate(Color _color)
                {
                    HSV hsv = new HSV(_color);
                    hsv.H = m_Hue;
                    return _color; 
                }));

                baseImageFilter.ProcessingMode = PROCESSING_MODE.Color;
                baseImageFilter.Execute(formFilterpictureBox1BackgroundImageClone).Dispose();
                formFilter.pictureBox1.BackgroundImage = formFilterpictureBox1BackgroundImageClone;
            };
        }
    }
}
